package main

import (
	"fmt"
	// log "github.com/alecthomas/log4go"
	"flag"
	// "github.com/Terry-Mao/gopush-cluster/perf"
	// "github.com/Terry-Mao/gopush-cluster/process"
	// "github.com/Terry-Mao/gopush-cluster/ver"
	"log"
	"net/http"
	_ "net/http/pprof"
	"runtime"
)

func main() {
	go func() {
		log.Println(http.ListenAndServe("localhost:6060", nil))
	}()
	// parse cmd-line arguments
	flag.Parse()
	fmt.Println("comet ver: \"%s\" start", "0.0.1")
	// init config
	if err := InitConfig(); err != nil {
		panic(err)
	}
	// set max routine
	runtime.GOMAXPROCS(Conf.MaxProc)

	// // init log
	// log.LoadConfiguration(Conf.Log)
	// defer log.Close()

	// // start pprof
	// perf.Init(Conf.PprofBind)
	// // create channel

	// init DBClient, 启动mongodb客户端
	if err := InitMongoClient(); err != nil{
		panic(err)
	}

	// 启动用户服务这一整套系统，rpc不用了
	if err := StartTCPService(); err != nil {
		panic(err)
	}

	// init signals, block wait signals
	// signalCH := InitSignal()
	// HandleSignal(signalCH)

	var c chan int
	select {
	case p := <-c:
		p -= 1
		return
	}
	// exit
	fmt.Println("UserService stop")
}
